package com.haha.extend.HeadBar;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;

import com.Long.library.R;
import com.haha.extend.button.StateBitmapImageButton;

/**
 * Created by Administrator on 2016/6/24 0024.
 */
public class ImageInLeftView extends BaseTitleBar{
    private Drawable leftImgSrcDrawable,leftImgBgDrawable;
    private StateBitmapImageButton leftImgBtn;
    public ImageInLeftView(Context context) {
        this(context,null);
    }

    public ImageInLeftView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public ImageInLeftView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void getAttrs(AttributeSet attrs) {
        super.getAttrs(attrs);
        TypedArray ta = context.obtainStyledAttributes(attrs,R.styleable.ImageInLeftView);
        leftImgSrcDrawable = ta.getDrawable(R.styleable.ImageInLeftView_leftImgSrcDrawable);
        leftImgBgDrawable = ta.getDrawable(R.styleable.ImageInLeftView_leftImgBgDrawable);
        ta.recycle();
    }

    @Override
    protected void findView() {
        super.findView();
        leftImgBtn = new StateBitmapImageButton(context);
        if (leftImgSrcDrawable != null){
            leftImgBtn.setBackgroundDrawable(leftImgSrcDrawable);
        }
        if (leftImgBgDrawable != null){
            leftImgBtn.setImageDrawable(leftImgBgDrawable);
        }
    }

    @Override
    public View getLeftView() {
        return leftImgBtn;
    }
}
